# coding=utf-8
import time
from framework.base_page import BasePage
from framework.logger import MyLog

# 实例化日志
log = MyLog.get_log()
logger = log.getlog()

class android_login(BasePage):
      #返回键
      # login_return_button='id=>com.gelonghui.glhapp:id/ib_back'
      #登录页标题
      # login_title='id=>com.gelonghui.glhapp:id/tv_main_title'
      #用户名
      # username_input='id=>com.gelonghui.glhapp:id/login_username'
      # #密码
      # password_input='id=>com.gelonghui.glhapp:id/login_password'
      # #登录按钮
      # login_button='id=>com.gelonghui.glhapp:id/btn_login'

      # # 右上角登录齿轮按钮
      # btn_right_login = 'xpath=>//*[@class="android.widget.ImageView" and index=0 and instance=2]'
      # if btn_right_login :
      #     print("\n ok.....")
      # else:
      #     print("\n eror....")
      # btn_right_login.click()
      '''
      # 点手机按钮登录
      el2 = driver.find_element_by_id("com.gelonghui.glhapp:id/iv_phone_login")
      el2.click()
      # 用户密码方式登录
      el3 = driver.find_element_by_id("com.gelonghui.glhapp:id/tv_psw_login")
      el3.click()
      # 点击用户名输入框
      el4 = driver.find_element_by_id("com.gelonghui.glhapp:id/et_phone_number")
      el4.click()
      el4.send_keys("156029179255")
      # 点击密码输入框
      el5 = driver.find_element_by_id("com.gelonghui.glhapp:id/et_psw")
      el5.click()
      el5.send_keys("aa123321")
      # 点击登录按钮
      el6 = driver.find_element_by_id("com.gelonghui.glhapp:id/tv_login")
      el8.click()
      # 登录成功后，进入个人页面，点右上角。。
      el9 = driver.find_element_by_xpath(
          "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.View/android.widget.FrameLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout[3]/android.widget.ImageView")
      el9.click()
      # 点注销按钮
      el10 = driver.find_element_by_xpath(
          "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView")
      el10.click()
      # 确认注销
      el11 = driver.find_element_by_id("com.gelonghui.glhapp:id/dialog_btn_ok")
      el11.click()

      def login_text(self,username,passwd):
          self.click(self.username_input)
          self.send_keys(self.username_input,username)
          logger.info('输入账号')
          self.click(self.password_input)
          self.send_keys(self.password_input,passwd)
          logger.info('输入密码')
          self.click(self.login_button)
          logger.info('点击登录按钮')
          time.sleep(1)

'''